<?php

/**
 * Created by Allen.
 * Date: 15-10-12
 * 会员模型
 */

class User_yeji_log_model extends HS_Model
{


    //获取结果集
    public function getList($where = array(), $limit = '20', $offset = '0', $order_by = 'id desc')
    {
        return $this->where($where)->limit($limit, $offset)->order_by($order_by)->find_all();
    }

    public function getUserYejiList($where)
    {
        return $this->select('id,user_id,sum(zhitui) as zhitui,sum(tuandui) as tuandui,count(tuandui >0 or null) tuandui_num ,count(zhitui >0 or null) zhitui_num')
            ->where($where)->group_by('user_id')->find_all();
    }

    //计算行数
    public function getCount($where = array())
    {
        return $this->where($where)->count();
    }

    //获取单个
    public function getOne($where)
    {
        return $this->where($where)->find();
    }

    //删除
    public function del($where)
    {
        return $this->where($where)->delete();
    }

    //编辑
    public function update($where, $data)
    {
        return $this->where($where)->edit($data);
    }

    //添加
    public function save($data)
    {
        if ($this->add($data)) {
            return $this->db->insert_id();
        }
    }
}
